﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.Profile;

namespace Possan.MySQL.WebTest
{
	public partial class _Default : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
				bindprops();
		}

		void bindprops()
		{
			if (User.Identity.IsAuthenticated)
			{
				TestProfile tp = (TestProfile)ProfileBase.Create(User.Identity.Name);

				TextBox tb = (TextBox)LoginView1.FindControl("tbProp1");
				if (tb != null)
					tb.Text = tp.Prop1;

				tb = (TextBox)LoginView1.FindControl("tbProp2");
				if (tb != null)
					tb.Text = tp.Prop2;
			}
		}

		protected void buLogout_Click(object sender, EventArgs e)
		{
			FormsAuthentication.SignOut();
			Response.Redirect("/");
		}
		
		protected void buSaveProps_Click(object sender, EventArgs e)
		{

			TestProfile tp = (TestProfile)ProfileBase.Create(User.Identity.Name);

			TextBox tb = (TextBox)LoginView1.FindControl("tbProp1");
			if (tb != null)
			{
				tp.Prop1 = tb.Text;
				Response.Write("tb.Text=" + tb.Text+ ", tp.Prop1=" + tp.Prop1 + "<br/>");
			}

			tb = (TextBox)LoginView1.FindControl("tbProp2");
			if (tb != null)
			{
				tp.Prop2 = tb.Text;
				Response.Write("tb.Text="+tb.Text+", tp.Prop2=" + tp.Prop2+ "<br/>");
			}

			tp.Save();

		}

		protected void Login1_LoggedIn2(object sender, EventArgs e)
		{
			bindprops();
		}
	}
}
